/*
 * Author: JacksonCoder
 * FileName: complateStack
 * Version: 1.0.0
 * Date: 2025/2/12
 */

import java.util.LinkedList;
import java.util.Queue;

public class complateStack<T> {
    private Queue<T> queue;
    private Queue<T> tempQueue;

    public complateStack() {
        queue = new LinkedList<>();
        tempQueue = new LinkedList<>();
    }

    public void push(T element) {
        queue.offer(element);
    }

    public T pop() {
        if (isEmpty()) {
            throw new RuntimeException("Stack is empty");
        }
        while (queue.size() > 1) {
            tempQueue.offer(queue.poll());
        }
        T element = queue.poll();
        Queue<T> temp = queue;
        queue = tempQueue;
        tempQueue = temp;
        return element;
    }

    public T peek() {
        if (isEmpty()) {
            throw new RuntimeException("Stack is empty");
        }
        while (queue.size() > 1) {
            tempQueue.offer(queue.poll());
        }
        T element = queue.poll();
        tempQueue.offer(element);
        Queue<T> temp = queue;
        queue = tempQueue;
        tempQueue = temp;
        return element;
    }

    public boolean isEmpty() {
        return queue.isEmpty();
    }


}
